<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    //
    /**
     * js中的json字符串
     *
     *
     *var obj="{'属性名':'属性值','属性名':{'属性名':'属性值'},'属性名':['值1','值1','值3']}"
     */
    var student = '{"name":"张三","age":12,"girlFriend":{"name":"村花","age":12}}'
    console.log(student)
    //判断数据类型
    console.log(typeof student)
    //将一个json的字符串转换为对象
    var parse = JSON.parse(student);
    console.log(parse)
    console.log(typeof parse)

    var person = {
        'name': '张小明',
        'age': 20,
        'girlFriend': {
            'name': '铁铃',
            'age': 23
        },
        'foods': ['苹果', '香蕉', '橘子', '葡萄'],
        'pets': [
            {
                'petName': '大黄',
                'petType': 'dog'
            },
            {
                'petName': '小花',
                'petType': 'cat'
            }
        ]
    }
    //获取对象中的值
    console.log(person.name)
    console.log(person.age)
    console.log(person.girlFriend.name)
    console.log(person.girlFriend.age)
    console.log(person.foods[0])
    console.log(person.foods[1])
    //将对象转换为JSON的字符串
    var s = JSON.stringify(parse);
    console.log(s)
    console.log(typeof s)
</script>
</html>